﻿using System;
using System.Collections.Generic;
using System.IO;
using AdaptiveAgents.Loggers;
using AdaptiveAgents.Experiments;
using AdaptiveAgents.Tools;
using AdaptiveAgents.Formulas;
using AdaptiveAgents.Runing_Tools;
using AdaptiveAgents.Running_Tools;
using AdaptiveAgents.Running_Tools.Agent_Lists;
using AdaptiveAgents.Running_Tools.Runnings_Packages;

namespace AdaptiveAgents
{
    public class AdaptiveAgents
    {
        //public static double epsilon; //hack while epsilon is global
        public static bool readDistributions = false; //hack: argument to say if we should read the distributions

        //a container for all the loggers of the game
        public static ContainerLogger logger = new ContainerLogger();

        public static void Main(String[] args)
        {
            #region oldStuff
            //String stamp = DateTime.Now.ToString("yyyy.MM.dd-HH.mm.ss");
            //AdaptiveAgents.logger.Add(new ScreenLogger());
            //AdaptiveAgents.logger.Add(new FileLogger("AdaptiveAgents-" + stamp + ".log"));

            //if (args.Length > 0) { epsilon = Double.Parse(args[0]); }
            //else
            //{
            //    logger.WriteLine(MessageType.HackMessage, "Setting epsilon to 0");
            //    epsilon = 0;
            //}

            //if (args.Length > 1)
            //{
            //    if (args[1].Equals("read"))
            //    {
            //        readDistributions = true;
            //    }
            //}
            #endregion

            ///First experiment to find best epsilon between 0.1 and 0.9
            #region Find Best Epsilon

            //logger.Add(new TalTempLogger());

            ////Experiment experiment = new EpsilonComparisonToCSVExperiment();//Last exp by matan
            //Experiment experiment = new FindBestEpsilonExperiment();

            //experiment.Logger = logger;

            ////Experiment experiment = new RectangleTstExperiment(new NullLogger());            
            //experiment.runExperiment();

            //Console.Read();
            //logger.WriteLine(MessageType.HackMessage, "Done...");

            //logger.Close();

            #endregion

            ///Second experiment according to what Dr Sarne ment
            #region Experiment 26/11/09

//            logger.Add(new TalTempLogger());

            //Create a new experiment
//            Experiment experiment = new FindBestEpsilonExperiment2();

//            experiment.Logger = logger;

            //Experiment experiment = new RectangleTstExperiment(new NullLogger());            
//            experiment.runExperiment();

//            Console.Read();
//            logger.WriteLine(MessageType.HackMessage, "Done...");

//            logger.Close();

            #endregion

            ///Third experiment according to what Dr Sarne Wants
            #region Experimanet 6/12/09

            //logger.Add(new TalTempLogger());

            ////Create a new experiment
            //Experiment experiment = new DeterministicExperiment();

            //experiment.Logger = logger;

            ////Experiment experiment = new RectangleTstExperiment(new NullLogger());            
            //experiment.runExperiment();

            //Console.Read();
            //logger.WriteLine(MessageType.HackMessage, "Done...");

            //logger.Close();

            #endregion


            #region ProjectCheckingTool


            //How to use Forst Formula Tool?

            // First, create ProjectCheckingTool obj
            //ProjectCheckingTool formula = new ProjectCheckingTool();


            //////// Second , create for each Experiment "Record" obj 
            //Record rec1 = new Record(0.1, 0.3, 0.7, 0.5, 0.9, 0.6, 147, 743, 110);
            //Record rec2 = new Record(0.3, 0.5, 0.4, 0.1, 0.7, 0.5, 202, 609, 189);
            //Record rec3 = new Record(0.6, 0.3, 0.7, 0.7, 0.4, 0.2, 879, 57, 64);
            //Record rec4 = new Record(0.2, 0.7, 0.5, 0.6, 0.7, 0.1, 278, 533, 189);
            //Record rec5 = new Record(0.2, 0.3, 0.5, 0.9, 0.3, 0.7, 764, 107, 129);
            //Record rec6 = new Record(0.7, 0.2, 0.4, 0.9, 0.1, 0.4, 550, 220, 230);
            //Record rec7 = new Record(0.2, 0.5, 0.6, 0.5, 0.2, 0.6, 201, 210, 589);
            //Record rec8 = new Record(0.3, 0.2, 0.9, 0.8, 0.4, 0.5, 716, 158, 126);
            //Record rec9 = new Record(0.3, 0.9, 0.8, 0.3, 0.9, 0.5, 307, 440, 253);
            //Record rec10 = new Record(0.9, 0.8, 0.4, 0.9, 0.2, 0.3, 434, 260, 306);
            //Record rec11 = new Record(0.2, 0.5, 0.6, 0.6, 0.3, 0.8, 214, 192, 594);
            //Record rec12 = new Record(0.5, 0.3, 0.7, 0.7, 0.6, 0.2, 607, 208, 185);
            //Record rec13 = new Record(0.9, 0.7, 0.5, 0.6, 0.3, 0.9, 223, 239, 538);
            //Record rec14 = new Record(0.9, 0.3, 0.6, 0.2, 0.7, 0.4, 161, 671, 168);
            //Record rec15 = new Record(0.1, 0.5, 0.6, 0.2, 0.6, 0.7, 235, 174, 591);
            //Record rec16 = new Record(0.3, 0.4, 0.8, 0.5, 0.2, 0.8, 280, 223, 497);
            //Record rec17 = new Record(0.4, 0.9, 0.3, 0.2, 0.7, 0.9, 169, 136, 695);
            //Record rec18 = new Record(0.5, 0.1, 0.4, 0.3, 0.8, 0.7, 64, 875, 61);
            //Record rec19 = new Record(0.4, 0.2, 0.8, 0.4, 0.2, 0.7, 229, 245, 526);
            //Record rec20 = new Record(0.6, 0.4, 0.7, 0.8, 0.7, 0.3, 558, 234, 208);    
          
            //// add all records to the formula
            //formula.addRecord(rec1);
            //formula.addRecord(rec2);
            //formula.addRecord(rec3);
            //formula.addRecord(rec4);
            //formula.addRecord(rec5);
            //formula.addRecord(rec6);
            //formula.addRecord(rec7);
            //formula.addRecord(rec8);
            //formula.addRecord(rec9);
            //formula.addRecord(rec10);
            //formula.addRecord(rec11);
            //formula.addRecord(rec12);
            //formula.addRecord(rec13);
            //formula.addRecord(rec14);
            //formula.addRecord(rec15);
            //formula.addRecord(rec16);
            //formula.addRecord(rec17);
            //formula.addRecord(rec18);
            //formula.addRecord(rec19);
            //formula.addRecord(rec20);    



            //solve the data
            //formula.solveDataBase();

            //print to SCV file
            //formula.printResultToCSVFile();


            #endregion


            #region AverageGradePerRound

            //AverageGradeRecord averageRec1 = new AverageGradeRecord(rec1, 0.804544, 1.0);
            //AverageGradeRecord averageRec2 = new AverageGradeRecord(rec2, 0.531125, 2.0);
            //AverageGradeRecord averageRec3 = new AverageGradeRecord(rec3, 0.662175, 3.0);
            //AverageGradeRecord averageRec4 = new AverageGradeRecord(rec4, 0.545485, 4.0);
            //AverageGradeRecord averageRec5 = new AverageGradeRecord(rec5, 0.804492, 5.0);
            //AverageGradeRecord averageRec6 = new AverageGradeRecord(rec6, 0.60358, 6.0);
            //AverageGradeRecord averageRec7 = new AverageGradeRecord(rec7, 0.506197, 7.0);
            //AverageGradeRecord averageRec8 = new AverageGradeRecord(rec8, 0.701664, 8.0);
            //AverageGradeRecord averageRec9 = new AverageGradeRecord(rec9, 0.609956, 9.0);
            //AverageGradeRecord averageRec10 = new AverageGradeRecord(rec10, 0.527106, 10.0);
            //AverageGradeRecord averageRec11 = new AverageGradeRecord(rec11, 0.670205, 11.0);
            //AverageGradeRecord averageRec12 = new AverageGradeRecord(rec12, 0.58386, 12.0);
            //AverageGradeRecord averageRec13 = new AverageGradeRecord(rec13, 0.690365, 13.0);
            //AverageGradeRecord averageRec14 = new AverageGradeRecord(rec14, 0.56893, 14.0);
            //AverageGradeRecord averageRec15 = new AverageGradeRecord(rec15, 0.560129, 15.0);
            //AverageGradeRecord averageRec16 = new AverageGradeRecord(rec16, 0.587738, 16.0);
            //AverageGradeRecord averageRec17 = new AverageGradeRecord(rec17, 0.752721, 17.0);
            //AverageGradeRecord averageRec18 = new AverageGradeRecord(rec18, 0.767867, 18.0);
            //AverageGradeRecord averageRec19 = new AverageGradeRecord(rec19, 0.518209, 19.0);
            //AverageGradeRecord averageRec20 = new AverageGradeRecord(rec20, 0.669992, 20.0);

            //AverageGradePerRound tool2 = new AverageGradePerRound();

            //tool2.addRecord(averageRec1);
            //tool2.addRecord(averageRec2);
            //tool2.addRecord(averageRec3);
            //tool2.addRecord(averageRec4);
            //tool2.addRecord(averageRec5);
            //tool2.addRecord(averageRec6);
            //tool2.addRecord(averageRec7);
            //tool2.addRecord(averageRec8);
            //tool2.addRecord(averageRec9);
            //tool2.addRecord(averageRec10);
            //tool2.addRecord(averageRec11);
            //tool2.addRecord(averageRec12);
            //tool2.addRecord(averageRec13);
            //tool2.addRecord(averageRec14);
            //tool2.addRecord(averageRec15);
            //tool2.addRecord(averageRec16);
            //tool2.addRecord(averageRec17);
            //tool2.addRecord(averageRec18);
            //tool2.addRecord(averageRec19);
            //tool2.addRecord(averageRec20);

            ////tool2.solveDataBase();
            ////tool2.printResultToCSVFile();


            //#endregion


            //#region splitTool according meeting at 10/12/2009 


            //FindTheBestAgentTool tool3 = new FindTheBestAgentTool();
            //tool3.addRecord(rec1);
            //tool3.addRecord(rec2);
            //tool3.addRecord(rec3);
            //tool3.addRecord(rec4);         
            //tool3.addRecord(rec5);
            //tool3.addRecord(rec6);
            //tool3.addRecord(rec7);
            //tool3.addRecord(rec8);
            //tool3.addRecord(rec9);
            //tool3.addRecord(rec10);
            //tool3.addRecord(rec11);
            //tool3.addRecord(rec12);
            //tool3.addRecord(rec13);
            //tool3.addRecord(rec14);
            //tool3.addRecord(rec15);
            //tool3.addRecord(rec16);
            //tool3.addRecord(rec17);
            //tool3.addRecord(rec18);
            //tool3.addRecord(rec19);
            //tool3.addRecord(rec20);

            //tool3.solveDataBase();
            //tool3.printResultToCSVFile();

            



            #endregion

            #region csv read experiment 02/01/10

  /*          logger.Add(new TalTempLogger());

            //Create a new experiment
            Experiment experiment = new FromCSVDeterministicExperiment();

            //Create new logger
            experiment.Logger = logger;

            //Start
            experiment.runExperiment();

            //Console.Read();
            logger.WriteLine(MessageType.HackMessage, "Done...");

            logger.Close();*/

            #endregion


            #region PDP Experimanet 9/2/10

            //logger.Add(new TalTempLogger());

            ////Create a new experiment
            //Experiment experiment = new PDPExperiment();

            //experiment.Logger = logger;

            ////Experiment experiment = new RectangleTstExperiment(new NullLogger());            
            //experiment.runExperiment();

            //Console.Read();
            //logger.WriteLine(MessageType.HackMessage, "Done...");

            //logger.Close();

            #endregion

            #region Find Best Epsilon

            //Experiment experiment = new FromCSVNewAdaptiveExperiment();

            //experiment.Logger = logger;

            ////Experiment experiment = new RectangleTstExperiment(new NullLogger());            
            //experiment.runExperiment();

            //Console.Read();
            //logger.WriteLine(MessageType.HackMessage, "Done...");

            //logger.Close();

            #endregion


            #region Olga N agents
            NAgentsExperiment exp = new NAgentsExperiment();
            exp.Logger = logger;

            //exp.runExperiment();

            #endregion

            #region Meir final step
            NormalAgentsListWithAdaptiveGreedyAgent k = new NormalAgentsListWithAdaptiveGreedyAgent(10);
            k.CreateList();
            List<string> agents = k.AgentsList;




            //InputPackage package = new InputPackage(10, 500, 10, "NewMDPGame", "NormalNAgentExperiment", false, "input1.csv", agents, logger);
            InputPackage package = new NormalNAgentsGameInputPackage(10, 500, 10, "input1.csv", "NormalAgentListWithGreedyAdaptiveAgent", logger);
            RunningTool tool = new RunningTool(package);
            tool.Run();
            

            #endregion

        }


    }
}

